package edu.cmu.ibill.controller;

import javax.servlet.http.HttpServletRequest;

import edu.cmu.ibill.databeans.PersonalBill;
import edu.cmu.ibill.databeans.User;
import edu.cmu.ibill.model.*;

public class ShowAllBillAction extends Action {
	
	UserDAO userDAO;
	PersonalBillDAO personalbillDAO;
	CategoryDictDAO catDAO;

	public ShowAllBillAction(Model model) {
		this.personalbillDAO = model.getPersonalBillDAO();
		this.userDAO = model.getUserDAO();
		this.catDAO = model.getCategoryDictDAO();
	}


	@Override
	public String getName() {
		return "showallbill.do";
	}

	@Override
	public String perform(HttpServletRequest request) {

		request.setAttribute("categorydict", catDAO.getAllCategoryNames());
		User user = (User) request.getSession(false).getAttribute("user");					
					
		PersonalBill[] pBills = personalbillDAO.LookupByUserId(user.getId());
		request.setAttribute("personalbills", pBills);
		return "manage.jsp";

	}

}
